<template>
    <div>
        <div class="homeMain-title">
            消息中心
        </div>
        <div class="mt-10">
            <Table :columns="messageCenterColumns" :data="messageCenterData" height="280"></Table>
            <div @click="goToMessage" class="newMoreStyle">
                查看更多>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'messageCenter',
        data () {
            return {
                messageCenterColumns: [
                    {
                        title: '消息内容',
                        key: 'content',
                        ellipsis: true,
                        maxWidth: 260,
                        render: (h, params) => {
                            return h('span', {
                                style: {
                                    cursor: 'pointer'
                                },
                                props: {},
                                on: {
                                    click: () => {
                                        this.goToBacklogModule(params.row.id, params.row.link, params.row.isRead);
                                    }
                                }
                            }, params.row.content);
                        }
                    },
                    {
                        title: '发起时间',
                        key: 'sendTime',
                        align: 'left',
                        render: (h, params) => {
                            return h('span', {

                            }, params.row.sendTime);
                        }
                    }
                    // {
                    //     title: '消息类型',
                    //     key: 'title',
                    //     align: 'center'
                    // }
                ],
                messageCenterData: []
            };
        },
        mounted () {
            this.loadMessageCenterData();
        },
        methods: {
            loadMessageCenterData () {
                depot.get({
                    url: this.URL.MESSAGE.FIND_MESSAGELOG_LIST_BY_PAGE,
                    cb: (data) => {
                        this.showSpin = false;
                        if (data.code === 0) {
                            if (data.data.content.length) {
                                if (data.data.content.length > 5) {
                                    this.messageCenterData = data.data.content.slice(0, 5);
                                } else {
                                    this.messageCenterData = data.data.content;
                                }
                            } else {
                                this.messageCenterData = [];
                            }
                        } else if (data.code === 999) {
                            this.$Message.error(data.message);
                        }
                    },
                    ce: (error) => {
                        this.showSpin = false;
                    }
                });
            },
            goToMessage () {
                this.$router.push({
                    name: 'myMessage'
                });
            }
    
        }
    };
</script>

<style scoped>

</style>